﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace DnD.Model
{
    [Table]
    class CardDeck
    {

         private int _id;
        private EntityRef<Deck> _deckRef;
        private EntityRef<Card> _cardRef;
        private bool _local;

        private int _deckID;
        private int _cardID;

        [Column]
        public int CardID {  get {return _cardID;}
            set
            {
              
                _cardID = value;
                OnPropertyChanged();
            } 
        }

        [Column]
        public int DeckID {  get {return _deckID;}
            set
            {
              
                _deckID = value;
                OnPropertyChanged();
            }
        }


        [Column(DbType = "INT NOT NULL IDENTITY", IsDbGenerated = true, IsPrimaryKey = true)]
        public int CardDeckId
        {
            get {return _id;}
            set
            {
              
                _id = value;
                OnPropertyChanged();
            }
        }

        [Association(Storage="_deckRef", ThisKey="DeckID")]
        public Deck DeckRef
        {
            get { return _deckRef.Entity; }
            set
            {
                _deckRef.Entity = value;
                DeckID = _deckRef.Entity.Id;
                OnPropertyChanged();
            }
        }


        [Association(Storage = "_cardRef", ThisKey = "CardID")]
        public Card CardRef
        {
            get { return _cardRef.Entity; }
            set
            {
                _cardRef.Entity = value;
                CardID = _cardRef.Entity.Id;
                OnPropertyChanged();
            }
        }

        [Column]
        public bool Local
        {
            get { return _local; }
            set
            {
                _local = value;
                OnPropertyChanged();
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (handler != null)
                handler(this, new PropertyChangedEventArgs(propertyName));
        }

    }
}
